<?php
class Admin_MailController extends Zend_Controller_Action{
	public function indexAction(){
		$mapper = new Application_Model_MailMapper();
		$page =  (int) $this->_getParam('page', 1);
		$paginator = Zend_Paginator::factory($mapper->fetchAll());
		$paginator	-> setItemCountPerPage(10)
					-> setCurrentPageNumber($page)
					-> setPageRange(3);
		$this->view->entries = $paginator;
	}
	public function readAction(){
		$id = (int) $this->_getParam('mail', null);
		if($id>0){
			$mapper = new Application_Model_MailMapper();
			$mail = $mapper->find($id, new Application_Model_Mail());
			if($mail===null){
				$this->_helper->redirector('index');
			}else{
				$mail->setRead(true);
				$mapper->save($mail);
				$this->view->mail = $mail;
			}
		}else{
			$this->_helper->redirector('index');
		}
	}
}